package org.huangrui.spark.scala.sql

import org.apache.spark.sql.{Dataset, Row, SparkSession}

import java.util.Properties

/**
 * @Author hr
 * @Create 2024-10-20 20:32 
 */
object SparkSQL07_Source_MySQL {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder.appName("SparkSQL07_Source_MySQL").master("local[2]").getOrCreate


    val properties: Properties = new Properties
    properties.setProperty("user", "root")
    properties.setProperty("password", "000000")
    val jdbc: Dataset[Row] = spark.read.jdbc("jdbc:mysql://hadoop121:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true", "ws2", properties)

    jdbc.write.jdbc("jdbc:mysql://hadoop121:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true", "ws2test", properties)

    jdbc.show()
    spark.stop()
  }
}
